package system.student.funtion.context;

import system.student.entity.login.LoginRequest;
import system.student.entity.login.LoginResponse;
import system.student.entity.login.LoginType;
import system.student.login.LoginStrategy;
import system.student.login.impl.EmailLoginStrategy;
import system.student.login.impl.PasswordLoginStrategy;
import system.student.login.impl.PhoneLoginStrategy;

import java.util.HashMap;

public class LoginStrategyContext {

    //  登录策略
    private static final HashMap<LoginType, LoginStrategy> map = new HashMap<>();
    static {
        map.put(LoginType.Password, new PasswordLoginStrategy());//  密码登录
        map.put(LoginType.Phone, new PhoneLoginStrategy());//  手机号登录
        map.put(LoginType.Email,new EmailLoginStrategy());//  邮箱登录
    }

    /**
     * 登录
     *
     * @param loginRequest 登录请求
     * @return 登录响应
     */
    public LoginResponse login(LoginRequest loginRequest) {
        System.out.println("开始登录");
        LoginType loginType = loginRequest.getLoginType();
        LoginStrategy loginStrategy = map.get(loginType);
        if (loginStrategy == null) {
            System.out.println("功能不支持");
            return null;
        }
        return loginStrategy.login(loginRequest);
    }
}
